<?php

namespace app\model;

class Industry extends \think\Model
{
    protected $schema = [
        "id" => "int",
        "title" => "varchar",
        "titlepic" => "varchar",
        "keywords" => "varchar",
        "summary" => "varchar",
        "type" => "int",
        "content" => "longtext",
        "create_time" => "datetime",
        "update_time" => "datetime"
    ];

    public static function getOne(int $id)
    {
        $data = self::find($id);
        
        return $data;
    }

    public static function queryPage()
    {
        return self::field('id,title,titlepic,type,create_time')->order('id desc')->paginate();
    }

    public static function getNextPrev(int $id)
    {
        $whereP = [];
        $whereN = [];

        $whereP[] = ['id', "<", $id];
        $whereN[] = ['id', ">", $id];

        $data_P = self::where($whereP)->field('id, title, create_time')->order("id desc")->limit(1)->find();
        $data_N = self::where($whereN)->field('id, title, create_time')->order("id asc")->limit(1)->find();

        return ['prev' => $data_P, 'next' => $data_N];
    }
}
